
Page({
    data: {
        hostList:'',
        searchPlaceholder:"",
        toView: "",
      character: ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "X", "Y", "Z"],
      zhuList:''
       
    },
    onLoad: function() {
     
    },
  onShow: function () {
   
  },
  setId: function (t) {
    var e = t.currentTarget.dataset.id;
    this.setData({
      toView: e
    });
  },
  search: function (t) {
    var e = this, i = t.detail.value, a = e.data.zhuList;
    if (i) {
      var r = {};
      for (var n in a) r[n] = [], a[n].forEach(function (t, e) {
        t.nickname.indexOf(i) > -1 && r[n].push(t);
      });
      e.setData({
        hostList: r
      });
    } else e.setData({
      hostList: a
    });
  },
  setuid: function (t) {
    var e = t.currentTarget.dataset.nickname, i = t.currentTarget.dataset.uid;
    this.triggerEvent("setuid", {
      nickname: e,
      uid: i
    });
  },
  scroll: function (t) {
    var e = t.detail.scrollTop;
    this.scrollY(e);
  },
  scrollY: function (t) {
    var hostList = this.data.hostList
    var list_key = Object.keys(hostList)
    console.log(list_key);
    const listHeight = this.data.listHeight
    if (0 == t || t < 0) {
      this.setData({
        currentIndex: list_key[0]
      }); 
      return;
    }

    // 在中间部分滚动
    for (let i = 0; i < listHeight.length - 1; i++) {
      let height1 = listHeight[i]
      let height2 = listHeight[i + 1]
      if (t >= height1 && t < height2) {
        this.setData({
          currentIndex: list_key[i]
        })
        return;
      }
    }
    // 当滚动到底部，且-newY大于最后一个元素的上限
    this.setData({
      currentIndex: list_key[listHeight.length - 2],
    })
  },
  _calculateHeight: function () {
    var lHeight = [],
      that = this;
    let height = 0;
    lHeight.push(height);
    var query = wx.createSelectorQuery();
    query.selectAll('.zimuzhu').boundingClientRect(function (rects) {
      var rect = rects,
        len = rect.length;
      for (let i = 0; i < len; i++) {
        height += rect[i].height;
        lHeight.push(height)
      }

    }).exec();
    var calHeight = setInterval(function () {
      if (lHeight != [0]) {
        that.setData({
          listHeight: lHeight
        });
        clearInterval(calHeight);
      }
    }, 1000)
  },

});